package br.usp.ime.origami.foldcut.gui.canvas;

import java.awt.BasicStroke;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

import br.usp.ime.origami.foldcut.gui.util.Figure;
import br.usp.ime.origami.foldcut.gui.util.OrigamiShape;

public class FirstPhaseCanvas extends Canvas
{

	private List<Figure> figures = new ArrayList<Figure>();

	public void setFigures(List<Figure> figures)
	{
		this.figures = figures;
	}

	@Override
	public void paint(Graphics g)
	{
		for (Figure figure : figures)
		{
			List<OrigamiShape> shapes = figure.getShapes();
			draw(g, shapes);
		}

	}


	public void update(Graphics g)
	{
		paint(g);
	}

	private void draw(Graphics g, List<OrigamiShape> shapes)
	{

		BufferedImage buffer = new BufferedImage(800, 800, BufferedImage.TYPE_INT_ARGB_PRE);

		Graphics2D graphics2D = buffer.createGraphics();
		graphics2D.setBackground(Color.WHITE);
		graphics2D.clearRect(0, 0, 800, 800);
		
		graphics2D.translate(20, 20);
		graphics2D.setStroke(new BasicStroke(2.0f));

		for (OrigamiShape myShape : shapes)
		{
			Color c = myShape.getColor();
			graphics2D.setColor(c);
			graphics2D.draw(myShape.getShape());
		}

		g.drawImage(buffer, 0, 0, buffer.getWidth(), buffer.getHeight(), null);
		// this.add(new JLabel(new ImageIcon(buffer)));
	}

}
